/**
 * 
 */
package sudoku.util;

import java.awt.Color;
import java.awt.Font;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

/**
 * @author Romet
 * 
 */
public class Config {

  public static String log = "sudoku.log";

  private BufferedReader lugeja;
  private PrintWriter kirjutaja;

  private String conf = "config.ini";
  private boolean debug = false;
  private String kaust = "";
  private int font9 = 1;
  private int font16 = 0;
  private boolean computerchoice = false;
  private boolean computerstatus = false;
  private boolean computerhelp = false;
  private boolean computerhinter = false;
  private boolean computersolver = false;
  private boolean computerchoicehelpremover = false;
  private String versioon = "4.1.3";
  private String databaseVersion = "-1";
  private String language = "eng";
  private List<String> kasutajad = new ArrayList<String>();
  private int ruudustik = 9;
  private int kast = 3;
  private int hetke_kasutaja = -1;
  private int location_x = -1;
  private int location_y = -1;
  private String nimi = "";
  private boolean symma = true;
  private boolean symm90 = false;
  private boolean symm180 = false;
  private boolean symm270 = false;
  private boolean symmvert = false;
  private boolean symmdiaga = false;
  private boolean symmhor = false;
  private boolean symmdiagm = false;
  private boolean c0 = false;
  private boolean d0 = false;
  private boolean v31 = false;
  private boolean v34 = false;
  private boolean v41 = false;
  private boolean v413 = false;

  public Color templahendus;
  public Color tempesialgne;

  private Color sudokuButton = Color.WHITE;
  private Color choiceButton = Color.WHITE;
  private Color mainPanel = Color.WHITE;
  private Color esialgne = Color.BLUE;
  private Color lahendus = Color.BLACK;
  private Color helpButton = Color.BLACK;

  private Font fonts9 = new Font(null, Font.BOLD, 31);
  private Font fonth9 = new Font(null, Font.BOLD, 9);
  private Font fonts16 = new Font(null, Font.BOLD, 25);
  private Font fonth16 = new Font(null, Font.BOLD, 8);

  public static Color GREEN = new Color(0, 204, 0);
  public static Color CYAN = new Color(0, 204, 204);
  public static Color ORANGE = Color.ORANGE;
  public static Color PINK = Color.PINK;
  public static Color LIGHTGREEN = new Color(204, 255, 204);

  private List<String> easy9 = new ArrayList<String>();
  private List<String> easy16 = new ArrayList<String>();
  private List<String> medium9 = new ArrayList<String>();
  private List<String> medium16 = new ArrayList<String>();
  private List<String> hard9 = new ArrayList<String>();
  private List<String> hard16 = new ArrayList<String>();
  private List<String> expert9 = new ArrayList<String>();
  private List<String> expert16 = new ArrayList<String>();
  private List<String> extreme9 = new ArrayList<String>();
  private List<String> extreme16 = new ArrayList<String>();

  /**
   * Kui leidub config fail, siis see meetod loeb viimati salvestatud
   * konfiguratsiooni.
   */
  public Config() {
    File logfile = new File(log);
    if (logfile.length() > 500000) {
      for (int i = 20; i >= 1; i--) {
        File cur = new File("sudoku.log" + i);
        if (cur.exists()) {
          if (i == 20) {
            cur.delete();
          } else {
            cur.renameTo(new File("sudoku.log" + (i + 1)));
          }
        }
      }
      logfile.renameTo(new File("sudoku.log1"));
    }
    if (new File(conf).exists()) {
      try {
        lugeja = new BufferedReader(new FileReader(conf));
        if (!lugeja.readLine().startsWith("debug=")) {
          lugeja.close();
          version3();
        } else {
          lugeja = new BufferedReader(new FileReader(conf));
          String rida = "";
          for (; rida != null;) {
            if (rida.startsWith("debug=")) {
              debug = Boolean.parseBoolean(rida.substring(6));
            } else if (rida.startsWith("folder=")) {
              kaust = rida.substring(7);
            } else if (rida.startsWith("font9=")) {
              font9 = Integer.parseInt(rida.substring(6));
              fonth9 = fonth9.deriveFont((float) fonth9.getSize() + font9);
              fonts9 = fonts9.deriveFont((float) fonts9.getSize() + font9);
            } else if (rida.startsWith("font16=")) {
              font16 = Integer.parseInt(rida.substring(7));
              fonth16 = fonth16.deriveFont((float) fonth16.getSize() + font16);
              fonts16 = fonts16.deriveFont((float) fonts16.getSize() + font16);
            } else if (rida.startsWith("computerchoice=")) {
              computerchoice = Boolean.valueOf(rida.substring(15)).booleanValue();
            } else if (rida.startsWith("computerstatus=")) {
              computerstatus = Boolean.valueOf(rida.substring(15)).booleanValue();
            } else if (rida.startsWith("computerhelp=")) {
              computerhelp = Boolean.valueOf(rida.substring(13)).booleanValue();
            } else if (rida.startsWith("computerhinter=")) {
              computerhinter = Boolean.valueOf(rida.substring(15)).booleanValue();
            } else if (rida.startsWith("computersolver=")) {
              computersolver = Boolean.valueOf(rida.substring(15)).booleanValue();
            } else if (rida.startsWith("computerchoicehelpremover=")) {
              computerchoicehelpremover = Boolean.valueOf(rida.substring(26)).booleanValue();
            } else if (rida.startsWith("user=")) {
              hetke_kasutaja = Integer.parseInt(rida.substring(5));
            } else if (rida.startsWith("location_x=")) {
              location_x = Integer.parseInt(rida.substring(11));
            } else if (rida.startsWith("location_y=")) {
              location_y = Integer.parseInt(rida.substring(11));
            } else if (rida.startsWith("language=")) {
              language = rida.substring(9);
            } else if (rida.startsWith("grid=")) {
              ruudustik = Integer.parseInt(rida.substring(5));
            } else if (rida.startsWith("boxes=")) {
              kast = Integer.parseInt(rida.substring(6));
            } else if (rida.startsWith("database=")) {
              databaseVersion = rida.substring(9);
            } else if (rida.startsWith("symma=")) {
              symma = Boolean.valueOf(rida.substring(6)).booleanValue();
            } else if (rida.startsWith("symm90=")) {
              symm90 = Boolean.valueOf(rida.substring(7)).booleanValue();
            } else if (rida.startsWith("symm180=")) {
              symm180 = Boolean.valueOf(rida.substring(8)).booleanValue();
            } else if (rida.startsWith("symm270=")) {
              symm270 = Boolean.valueOf(rida.substring(8)).booleanValue();
            } else if (rida.startsWith("symmvert=")) {
              symmvert = Boolean.valueOf(rida.substring(9)).booleanValue();
            } else if (rida.startsWith("symmdiaga=")) {
              symmdiaga = Boolean.valueOf(rida.substring(10)).booleanValue();
            } else if (rida.startsWith("symmhor=")) {
              symmhor = Boolean.valueOf(rida.substring(8)).booleanValue();
            } else if (rida.startsWith("symmdiagm=")) {
              symmdiagm = Boolean.valueOf(rida.substring(10)).booleanValue();
            } else if (rida.startsWith("users=")) {
              kasutajad.add(rida.substring(6));
            } else if (rida.startsWith("easy9=")) {
              easy9.add(rida.substring(6));
            } else if (rida.startsWith("medium9=")) {
              medium9.add(rida.substring(8));
            } else if (rida.startsWith("hard9=")) {
              hard9.add(rida.substring(6));
            } else if (rida.startsWith("expert9=")) {
              expert9.add(rida.substring(8));
            } else if (rida.startsWith("extreme9=")) {
              extreme9.add(rida.substring(9));
            } else if (rida.startsWith("easy16=")) {
              easy16.add(rida.substring(7));
            } else if (rida.startsWith("medium16=")) {
              medium16.add(rida.substring(9));
            } else if (rida.startsWith("hard16=")) {
              hard16.add(rida.substring(7));
            } else if (rida.startsWith("expert16=")) {
              expert16.add(rida.substring(9));
            } else if (rida.startsWith("extreme16=")) {
              extreme16.add(rida.substring(10));
            } else if (rida.startsWith("c0=")) {
              c0 = Boolean.valueOf(rida.substring(3)).booleanValue();
            } else if (rida.startsWith("d0=")) {
              d0 = Boolean.valueOf(rida.substring(3)).booleanValue();
            } else if (rida.startsWith("v31=")) {
              v31 = Boolean.valueOf(rida.substring(4)).booleanValue();
            } else if (rida.startsWith("v34=")) {
              v34 = Boolean.valueOf(rida.substring(4)).booleanValue();
            } else if (rida.startsWith("v41=")) {
              v41 = Boolean.valueOf(rida.substring(4)).booleanValue();
            } else if (rida.startsWith("v413=")) {
              v413 = Boolean.valueOf(rida.substring(5)).booleanValue();
            }
            rida = lugeja.readLine();
          }
        }
        lugeja.close();
        setKasutajad(kasutajad);
        salvesta();
      } catch (FileNotFoundException er) {
        Config.log(er.getClass().toString() + ": " + er.getMessage(), er.getStackTrace());
      } catch (IOException er) {
        Config.log(er.getClass().toString() + ": " + er.getMessage(), er.getStackTrace());
      } catch (NumberFormatException er) {
        Config.log(er.getClass().toString() + ": " + er.getMessage(), er.getStackTrace());
      }
    } else {
      salvesta();
    }
  }

  /**
   * Tagastab valikunupu tausta värvi.
   * 
   * @return valikunupu taustavärv
   */
  public Color getChoiceButton() {
    return choiceButton;
  }

  public String getDatabaseVersion() {
    return databaseVersion;
  }

  public synchronized List<String> getEasy() {
    if (ruudustik == 9) {
      return easy9;
    } else {
      return easy16;
    }
  }

  /**
   * Tagastab algseisu teksti värvi.
   * 
   * @return algseisu teksti värv
   */
  public Color getEsialgne() {
    return esialgne;
  }

  public synchronized List<String> getExpert() {
    if (ruudustik == 9) {
      return expert9;
    } else {
      return expert16;
    }
  }

  public synchronized List<String> getExtreme() {
    if (ruudustik == 9) {
      return extreme9;
    } else {
      return extreme16;
    }
  }

  public int getFont9() {
    return font9;
  }

  public int getFont16() {
    return font16;
  }

  public Font getFonth(int i) {
    if (i == 9) {
      return fonth9;
    }
    return fonth16;
  }

  public Font getFonts(int i) {
    if (i == 9) {
      return fonts9;
    }
    return fonts16;
  }

  public synchronized List<String> getHard() {
    if (ruudustik == 9) {
      return hard9;
    } else {
      return hard16;
    }
  }

  public Font getHelpFont() {
    if (ruudustik == 9) {
      return fonth9;
    }
    return fonth16;
  }

  public Color getHelpButton() {
    return helpButton;
  }

  /**
   * @return hetkekasutaja
   */
  public int getHetke_kasutaja() {
    return hetke_kasutaja;
  }

  public int getLocation_x() {
    return location_x;
  }

  public int getLocation_y() {
    return location_y;
  }

  public int getKast() {
    return kast;
  }

  public List<String> getKasutajad() {
    return kasutajad;
  }

  /**
   * Tagastab viimati kasutatud kausta asukoha.
   * 
   * @return viimati kasutatud kausta asukoht
   */
  public String getKaust() {
    return kaust;
  }

  /**
   * Tagastab lahenduse teksti värvi.
   * 
   * @return lahenduse teksti värv
   */
  public Color getLahendus() {
    return lahendus;
  }

  public String getLanguage() {
    return language;
  }

  /**
   * Tagastab põhiakna tausta värvi.
   * 
   * @return põhiakna tausta värv
   */
  public Color getMainPanel() {
    return mainPanel;
  }

  public synchronized List<String> getMedium() {
    if (ruudustik == 9) {
      return medium9;
    } else {
      return medium16;
    }
  }

  /**
   * @return kasutaja nimi
   */
  public String getNimi() {
    return nimi;
  }

  public int getRuudustik() {
    return ruudustik;
  }

  /**
   * Tagastab nuppude tausta värvi.
   * 
   * @return nuppude tausta värv
   */
  public Color getSudokuButton() {
    return sudokuButton;
  }

  public Font getSudokuFont() {
    if (ruudustik == 9) {
      return fonts9;
    }
    return fonts16;
  }

  public String getVersioon() {
    return versioon;
  }

  public boolean isC0() {
    return c0;
  }

  public boolean isD0() {
    return d0;
  }

  public boolean isComputerchoice() {
    return computerchoice;
  }

  public boolean isComputerchoicehelpremover() {
    return computerchoicehelpremover;
  }

  public boolean isComputerhelp() {
    return computerhelp;
  }

  public boolean isComputerhinter() {
    return computerhinter;
  }

  public boolean isComputersolver() {
    return computersolver;
  }

  public boolean isComputerstatus() {
    return computerstatus;
  }

  public boolean isDebug() {
    return debug;
  }

  public boolean isSymm180() {
    return symm180;
  }

  public boolean isSymm270() {
    return symm270;
  }

  public boolean isSymm90() {
    return symm90;
  }

  public boolean isSymma() {
    return symma;
  }

  public boolean isSymmdiaga() {
    return symmdiaga;
  }

  public boolean isSymmdiagm() {
    return symmdiagm;
  }

  public boolean isSymmhor() {
    return symmhor;
  }

  public boolean isSymmvert() {
    return symmvert;
  }

  public boolean isV31() {
    return v31;
  }

  public boolean isV34() {
    return v34;
  }

  public boolean isV41() {
    return v41;
  }

  public boolean isV413() {
    return v413;
  }

  public static void log(Object o) {
    try {
      PrintWriter wr = new PrintWriter(new FileWriter(log, true));
      StringBuffer sb = new StringBuffer();
      Calendar cal = Calendar.getInstance();
      sb.append(cal.get(Calendar.DAY_OF_MONTH) + ".");
      sb.append((cal.get(Calendar.MONTH) + 1) + ".");
      sb.append(cal.get(Calendar.YEAR) + " ");
      sb.append(cal.get(Calendar.HOUR_OF_DAY) + ":");
      sb.append(cal.get(Calendar.MINUTE) + ":");
      sb.append(cal.get(Calendar.SECOND) + ",");
      sb.append(cal.get(Calendar.MILLISECOND));
      sb.append(" --> " + o);
      wr.println(sb.toString());
      // System.out.println(sb.toString());
      wr.flush();
      wr.close();
    } catch (Exception e) {
      Config.log(e.getClass().toString() + ": " + e.getMessage(), e.getStackTrace());
    }
  }

  public static void log(String cause, StackTraceElement[] e) {
    try {
      PrintWriter wr = new PrintWriter(new FileWriter(log, true));
      StringBuffer sb = new StringBuffer();
      Calendar cal = Calendar.getInstance();
      sb.append(cal.get(Calendar.DAY_OF_MONTH) + ".");
      sb.append((cal.get(Calendar.MONTH) + 1) + ".");
      sb.append(cal.get(Calendar.YEAR) + " ");
      sb.append(cal.get(Calendar.HOUR_OF_DAY) + ":");
      sb.append(cal.get(Calendar.MINUTE) + ":");
      sb.append(cal.get(Calendar.SECOND) + ",");
      sb.append(cal.get(Calendar.MILLISECOND));
      sb.append(" --> ");
      int curlen = sb.toString().length();
      sb.append(cause + " ");
      // System.out.println(sb.toString());
      wr.println(sb.toString());
      for (int i = 0; i < e.length; i++) {
        sb = new StringBuffer();
        for (int j = 0; j < curlen + 4; j++) {
          sb.append(" ");
        }
        sb.append("at  ");
        sb.append(e[i]);
        // System.out.println(sb.toString());
        wr.println(sb.toString());
      }
      wr.flush();
      wr.close();
    } catch (Exception er) {
      Config.log(er.getClass().toString() + ": " + er.getMessage(), er.getStackTrace());
    }
  }

  public void nulliGenereeritud() {
    easy9 = new ArrayList<String>();
    medium9 = new ArrayList<String>();
    hard9 = new ArrayList<String>();
    easy16 = new ArrayList<String>();
    medium16 = new ArrayList<String>();
    hard16 = new ArrayList<String>();
    expert9 = new ArrayList<String>();
    expert16 = new ArrayList<String>();
    extreme9 = new ArrayList<String>();
    extreme16 = new ArrayList<String>();
    salvesta();
  }

  /**
   * Salvestab kasutaja konfiguratsiooni
   */
  public synchronized void salvesta() {
    try {
      kirjutaja = new PrintWriter(new FileWriter(conf));
      kirjutaja.println("debug=" + debug);
      kirjutaja.println("folder=" + kaust);
      kirjutaja.println("font9=" + font9);
      kirjutaja.println("font16=" + font16);
      kirjutaja.println("computerchoice=" + computerchoice);
      kirjutaja.println("computerstatus=" + computerstatus);
      kirjutaja.println("computerhelp=" + computerhelp);
      kirjutaja.println("computerhinter=" + computerhinter);
      kirjutaja.println("computersolver=" + computersolver);
      kirjutaja.println("computerchoicehelpremover=" + computerchoicehelpremover);
      kirjutaja.println("user=" + hetke_kasutaja);
      kirjutaja.println("location_x=" + location_x);
      kirjutaja.println("location_y=" + location_y);
      kirjutaja.println("language=" + language);
      kirjutaja.println("grid=" + ruudustik);
      kirjutaja.println("boxes=" + kast);
      kirjutaja.println("database=" + databaseVersion);
      kirjutaja.println("symma=" + symma);
      kirjutaja.println("symm90=" + symm90);
      kirjutaja.println("symm180=" + symm180);
      kirjutaja.println("symm270=" + symm270);
      kirjutaja.println("symmvert=" + symmvert);
      kirjutaja.println("symmdiaga=" + symmdiaga);
      kirjutaja.println("symmhor=" + symmhor);
      kirjutaja.println("symmdiagm=" + symmdiagm);
      kirjutaja.println("c0=" + c0);
      kirjutaja.println("d0=" + d0);
      kirjutaja.println("v31=" + v31);
      kirjutaja.println("v34=" + v34);
      kirjutaja.println("v41=" + v41);
      kirjutaja.println("v413=" + v413);
      kirjutaja.flush();
      for (int i = 0; i < kasutajad.size(); i++) {
        kirjutaja.println("users=" + kasutajad.get(i));
        kirjutaja.flush();
      }
      for (int i = 0; i < easy9.size(); i++) {
        kirjutaja.println("easy9=" + easy9.get(i));
        kirjutaja.flush();
      }
      for (int i = 0; i < medium9.size(); i++) {
        kirjutaja.println("medium9=" + medium9.get(i));
        kirjutaja.flush();
      }
      for (int i = 0; i < hard9.size(); i++) {
        kirjutaja.println("hard9=" + hard9.get(i));
        kirjutaja.flush();
      }
      for (int i = 0; i < expert9.size(); i++) {
        kirjutaja.println("expert9=" + expert9.get(i));
        kirjutaja.flush();
      }
      for (int i = 0; i < extreme9.size(); i++) {
        kirjutaja.println("extreme9=" + extreme9.get(i));
        kirjutaja.flush();
      }
      for (int i = 0; i < easy16.size(); i++) {
        kirjutaja.println("easy16=" + easy16.get(i));
        kirjutaja.flush();
      }
      for (int i = 0; i < medium16.size(); i++) {
        kirjutaja.println("medium16=" + medium16.get(i));
        kirjutaja.flush();
      }
      for (int i = 0; i < hard16.size(); i++) {
        kirjutaja.println("hard16=" + hard16.get(i));
        kirjutaja.flush();
      }
      for (int i = 0; i < expert16.size(); i++) {
        kirjutaja.println("expert16=" + expert16.get(i));
        kirjutaja.flush();
      }
      for (int i = 0; i < extreme16.size(); i++) {
        kirjutaja.println("extreme16=" + extreme16.get(i));
        kirjutaja.flush();
      }
      kirjutaja.close();
    } catch (FileNotFoundException e) {
      Config.log(e.getClass().toString() + ": " + e.getMessage(), e.getStackTrace());
    } catch (IOException e) {
      Config.log(e.getClass().toString() + ": " + e.getMessage(), e.getStackTrace());
    }
  }

  public void setC0(boolean c0) {
    this.c0 = c0;
    salvesta();
  }

  public void setD0(boolean d0) {
    this.d0 = d0;
    salvesta();
  }

  public void setComputerchoice(boolean computerchoice) {
    this.computerchoice = computerchoice;
  }

  public void setComputerchoicehelpremover(boolean computerchoicehelpremover) {
    this.computerchoicehelpremover = computerchoicehelpremover;
  }

  public void setComputerhelp(boolean computerhelp) {
    this.computerhelp = computerhelp;
  }

  public void setComputerhinter(boolean computerhinter) {
    this.computerhinter = computerhinter;
  }

  public void setComputersolver(boolean computersolver) {
    this.computersolver = computersolver;
  }

  public void setComputerstatus(boolean computerstatus) {
    this.computerstatus = computerstatus;
  }

  public void setDatabaseVersion(String databaseVersion) {
    this.databaseVersion = databaseVersion;
    salvesta();
  }

  public void setFonts(int font9, int font16) {
    fonth16 = fonth16.deriveFont((float) fonth16.getSize() + font16 - this.font16);
    fonth9 = fonth9.deriveFont((float) fonth9.getSize() + font9 - this.font9);
    fonts16 = fonts16.deriveFont((float) fonts16.getSize() + font16 - this.font16);
    fonts9 = fonts9.deriveFont((float) fonts9.getSize() + font9 - this.font9);
    this.font9 = font9;
    this.font16 = font16;
    salvesta();
  }

  public void setHetke_kasutaja(int hetke_kasutaja) {
    this.hetke_kasutaja = hetke_kasutaja;
    salvesta();
  }

  public void setLocation_x(int location_x) {
    this.location_x = location_x;
  }

  public void setLocation_y(int location_y) {
    this.location_y = location_y;
  }

  public void setKast(int kast) {
    this.kast = kast;
    salvesta();
  }

  public void setKasutajad(List<String> kasutajad) {
    this.kasutajad = kasutajad;
    tempesialgne = esialgne;
    templahendus = lahendus;
    salvesta();
    if (hetke_kasutaja == -1) {
      if (language.equals("est")) {
        nimi = "Mängija";
      }
      if (language.equals("eng")) {
        nimi = "User";
      }
      sudokuButton = Color.WHITE;
      choiceButton = Color.WHITE;
      // mainPanel = Color.WHITE;
      esialgne = Color.BLUE;
      lahendus = Color.BLACK;
      helpButton = Color.MAGENTA;
    } else {
      String[] s = (kasutajad.get(hetke_kasutaja)).split(":")[1].split(";");
      nimi = (kasutajad.get(hetke_kasutaja)).split(":")[0];
      esialgne = new Color(Integer.parseInt(s[0].split(",")[0]), Integer.parseInt(s[0].split(",")[1]), Integer.parseInt(s[0].split(",")[2]));
      lahendus = new Color(Integer.parseInt(s[1].split(",")[0]), Integer.parseInt(s[1].split(",")[1]), Integer.parseInt(s[1].split(",")[2]));
      helpButton = new Color(Integer.parseInt(s[2].split(",")[0]), Integer.parseInt(s[2].split(",")[1]),
          Integer.parseInt(s[2].split(",")[2]));
    }
  }

  /**
   * Sätib uue kausta ja salvestab kogu konfiguratsiooni uuesti.
   * 
   * @param kaust
   *          viimati kastutatud kaust
   */
  public void setKaust(String kaust) {
    this.kaust = kaust;
    salvesta();
  }

  public void setLanguage(String language) {
    this.language = language;
    salvesta();
  }

  public void setNimi(String nimi) {
    this.nimi = nimi;
  }

  public void setRuudustik(int ruudustik) {
    this.ruudustik = ruudustik;
    salvesta();
  }

  public void setSymm180(boolean symm180) {
    this.symm180 = symm180;
  }

  public void setSymm270(boolean symm270) {
    this.symm270 = symm270;
  }

  public void setSymm90(boolean symm90) {
    this.symm90 = symm90;
  }

  public void setSymma(boolean symma) {
    this.symma = symma;
  }

  public void setSymmhor(boolean symmhor) {
    this.symmhor = symmhor;
  }

  public void setSymmdiaga(boolean symmdiaga) {
    this.symmdiaga = symmdiaga;
  }

  public void setSymmdiagm(boolean symmdiagm) {
    this.symmdiagm = symmdiagm;
  }

  public void setSymmvert(boolean symmvert) {
    this.symmvert = symmvert;
  }

  public void setV31(boolean v31) {
    this.v31 = v31;
    salvesta();
  }

  public void setV34(boolean v34) {
    this.v34 = v34;
  }

  public void setV41(boolean v41) {
    this.v41 = v41;
    salvesta();
  }

  public void setV413(boolean v413) {
    this.v413 = v413;
    salvesta();
  }

  public void version3() {
    try {
      lugeja = new BufferedReader(new FileReader(conf));
      String rida = "";
      for (int i = 0; rida != null; i++) {
        if (i == 1) {
          kaust = rida;
        }
        if (i == 3) {
          hetke_kasutaja = Integer.parseInt(rida);
        }
        if (i == 4) {
          language = rida;
        }
        if (i == 5) {
          ruudustik = Integer.parseInt(rida);
        }
        if (i == 6) {
          kast = Integer.parseInt(rida);
        }
        if (i > 6) {
          kasutajad.add(rida);
        }
        rida = lugeja.readLine();
        if (rida == null && i < 6) {
          Integer.parseInt("blaa");
        }
      }
      lugeja.close();
      for (int i = 0; i < kasutajad.size(); i++) {
        String[] s = (kasutajad.get(i)).split(":")[1].split(";");
        String ss = (kasutajad.get(i)).split(":")[0] + ":";
        ss += s[2].split(",")[0] + "," + s[2].split(",")[1] + "," + s[2].split(",")[2] + ";";
        ss += s[3].split(",")[0] + "," + s[3].split(",")[1] + "," + s[3].split(",")[2] + ";";
        ss += s[4].split(",")[0] + "," + s[4].split(",")[1] + "," + s[4].split(",")[2];
        kasutajad.set(i, ss);
      }
      salvesta();
    } catch (FileNotFoundException er) {
      Config.log(er.getClass().toString() + ": " + er.getMessage(), er.getStackTrace());
    } catch (IOException er) {
      Config.log(er.getClass().toString() + ": " + er.getMessage(), er.getStackTrace());
    } catch (NumberFormatException er) {
      try {
        lugeja = new BufferedReader(new FileReader(conf));
        ;
        for (int i = 0; i < kasutajad.size(); i++) {
          lugeja.readLine();
        }
        String rida = "";
        for (int i = 0; rida != null; i++) {
          if (i == 1) {
            kaust = rida;
          }
          if (i == 3) {
            hetke_kasutaja = Integer.parseInt(rida);
          }
          if (i == 4) {
            ruudustik = Integer.parseInt(rida);
          }
          if (i == 5) {
            kast = Integer.parseInt(rida);
          }
          if (i > 5) {
            kasutajad.add(rida);
          }
          rida = lugeja.readLine();
        }
        lugeja.close();
        language = "est";
        for (int i = 0; i < kasutajad.size(); i++) {
          String[] s = (kasutajad.get(i)).split(":")[1].split(";");
          String ss = (kasutajad.get(i)).split(":")[0] + ":";
          ss += s[2].split(",")[0] + "," + s[2].split(",")[1] + "," + s[2].split(",")[2] + ";";
          ss += s[3].split(",")[0] + "," + s[3].split(",")[1] + "," + s[3].split(",")[2] + ";";
          ss += s[4].split(",")[0] + "," + s[4].split(",")[1] + "," + s[4].split(",")[2];
          kasutajad.set(i, ss);
        }
        salvesta();
      } catch (FileNotFoundException err) {
        Config.log(err.getClass().toString() + ": " + err.getMessage(), err.getStackTrace());
      } catch (IOException err) {
        Config.log(err.getClass().toString() + ": " + err.getMessage(), err.getStackTrace());
      } catch (NumberFormatException err) {
        try {
          lugeja = new BufferedReader(new FileReader(conf));
          ;
          for (int i = 0; i < kasutajad.size(); i++) {
            lugeja.readLine();
          }
          String rida = "";
          for (int i = 0; rida != null; i++) {
            if (i == 1) {
              kaust = rida;
            }
            if (i == 3) {
              hetke_kasutaja = Integer.parseInt(rida);
            }
            if (i > 3) {
              kasutajad.add(rida);
            }
            rida = lugeja.readLine();
          }
          lugeja.close();
          language = "est";
          for (int i = 0; i < kasutajad.size(); i++) {
            String[] s = (kasutajad.get(i)).split(":")[1].split(";");
            String ss = (kasutajad.get(i)).split(":")[0] + ":";
            ss += s[2].split(",")[0] + "," + s[2].split(",")[1] + "," + s[2].split(",")[2] + ";";
            ss += s[3].split(",")[0] + "," + s[3].split(",")[1] + "," + s[3].split(",")[2] + ";";
            ss += s[4].split(",")[0] + "," + s[4].split(",")[1] + "," + s[4].split(",")[2];
            kasutajad.set(i, ss);
          }
          salvesta();
        } catch (FileNotFoundException e) {
          Config.log(e.getClass().toString() + ": " + e.getMessage(), e.getStackTrace());
        } catch (IOException e) {
          Config.log(e.getClass().toString() + ": " + e.getMessage(), e.getStackTrace());
        }
      }
    }
  }
}
